import { Controller, Get, Post } from '@nestjs/common';
import { UserService } from './user.service';
import { ConfigService } from '@nestjs/config';
import { ConfigEnum } from '../enum/config.enum';
import { User } from './user.entity';

@Controller('user')
export class UserController {
    constructor(private readonly userService: UserService, private readonly configService: ConfigService) {}



    @Get('infoo')
    getUser(): any {
        const user = this.userService.getUser();
        const db = this.configService.get<string>(ConfigEnum.DB);

        console.log(db);
        return user
    }

    @Get('userList')
    getUserList(): any {
        const userInfo = this.userService.findAll();
        return userInfo;
    }

    @Post("add")
    addUser(): any {
        const user = {username: 'long1dfu sun', password: '123456'} as User;
        const createResult = this.userService.create(user);

        return createResult;
    }

    @Post("update")
    updateUser(): any {
        const userId = 1;
        const user = {id: 1, username: 'wagong', password: '123456'} as User;
        const updateResult = this.userService.update(userId, user);
        return updateResult;
    }

    @Post("delete")
    deleteUser(): any {
        const userId = 7;
        const deleteResult = this.userService.remove(userId);
        return deleteResult;
    }

    @Get('findProfile')
    findProfile(): any {
        const userId = 3;
        return this.userService.findProfile(userId);
    }

    @Get('findUserLogs')
    findUserLogs(): any {
        const userId = 3;
        return this.userService.findUserLogs(userId);
    }

}
